<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8" import="java.util.List,com.dao.Message,java.util.List,com.dao.Users"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>留言板</title>
</head>
<body>
	<% 
		Users u=(Users)request.getSession().getAttribute("UserMessage"); 
	%>
	<h1>留言板</h1>
	<form action="<%=request.getContextPath() %>/users/control.jsp" method="post">
			<input name="submittype" type="submit" value="用户管理"/>
  	   </form>
	<%
		List<Message> list=(List<Message>)request.getAttribute("list");
		for(Message obj:list){
	%>
	<table width="600" border="1">
		<tr>
			<td>ID:</td>
			<td><%=obj.getId() %></td>
		</tr>
		<tr>
			<td>账号：</td>
			<td><%=obj.getMusername() %></td>
		</tr>
		<tr>
			<td>昵称：</td>
			<td><%=obj.getAuthor() %></td>
		</tr>
		<tr>
			<td>主题：</td>
			<td><%=obj.getTitle() %><% String name1=URLEncoder.encode(obj.getTitle(),"utf-8"); %></td>
		</tr>
		<tr>
			<td>内容：</td>
			<td><%=obj.getContent() %><% String name2=URLEncoder.encode(obj.getContent(),"utf-8"); %></td>
		</tr>
		<tr>
			<td>日期：</td>
			<td><%=obj.getDate() %></td>
		</tr>
		<%
			if(u.getUsername().equals(obj.getMusername())) {
		%>
		<tr>
			<td><a href="<%=request.getContextPath() %>/message/updateMessage.jsp?title=<%=name1 %>&content=<%=name2 %>&id=<%=obj.getId() %>">修改留言</a></td>
			<td><a href="<%=request.getContextPath() %>/MessageServlet?submittype=delete&Musername=<%=obj.getMusername() %>&id=<%=obj.getId() %>">删除留言</a></td>
		</tr>
		<%
			}
		%>
	</table>
	<%
		}
	%>
	<form action="message/addMessage.jsp" method="post">
			<input name="submittype" type="submit" value="添加留言"/>
  	   </form>
	<form action="<%=request.getContextPath() %>/MessageServlet" method="post">
			<input name="submittype" type="submit" value="查询本人留言"/>
  	   </form>
  	   <form action="<%=request.getContextPath() %>/MessageServlet" method="post">
			查询指定用户留言：<input name="name" type="text" value="">
			<input name="submittype" type="submit" value="查询指定用户留言"/><br>
		</form>
	<form action="<%=request.getContextPath() %>/UsersServlet" method="post">
		<input type="submit" name="submittype" value="退出登录">
	</form>
	<p>${error}</p>
</body>
</html>